<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
  <title>部门管理</title>
  <script type="text/javascript">
    $(function() {
      $('.delete_dept').click(function() {
        $('#confirm_delete').data('dept_id', $(this).attr('dept_id')).data('dept_name', $(this).attr('dept_name')).modal('show');
      });
      $('#confirm_delete').on('shown', function() {
        $(this).find('span').text($(this).data('dept_name'));
        $('#delete_action').attr('href', '${ctx}/hr/option/department/delete/' + $(this).data('dept_id'));
      });
    });
  </script>
</head>

<body>
  <c:if test="${not empty message}">
    <div id="message" class="alert alert-success"><button data-dismiss="alert" class="close">×</button>${message}</div>
  </c:if>
  <table id="contentTable" class="table table-striped table-bordered table-condensed">
    <thead><tr><th width="60%">名称</th><th width="20%">排序</th><th width="20%">管理</th></tr></thead>
    <tbody>
    <c:forEach items="${departments.content}" var="department">
      <tr>
        <td><a href="${ctx}/hr/option/department/update/${department.id}">${department.name}</a></td>
        <td>${department.order}</td>
        <td><a class="btn delete_dept" dept_id="${department.id}" dept_name="${department.name}">删除</a>
      </tr>
    </c:forEach>
    </tbody>
  </table>

  <div><a class="btn" href="${ctx}/hr/option/department/create">创建部门</a></div>

  <div class="modal hide" id="confirm_delete">
    <div class="modal-header">
      <a class="close" data-dismiss="modal">×</a>
      <h3>删除确认</h3>
    </div>
    <div class="modal-body">
      <p>确认要删除部门“<span></span>”？</p>
    </div>
    <div class="modal-footer">
      <a class="btn" data-dismiss="modal">取消</a>
      <a id="delete_action" class="btn btn-primary">确定</a>
    </div>
  </div>
</body>
</html>
